﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NeuralNetworks.ActivationFunctions;
using System.Collections;
using NeuralNetworks.Layers;

namespace NeuralNetworks.Neurons
{
    public class ActivationNeuron : Neuron
    {
        private IActivationFunction function;
        private double error;
        private double biasEnabled = 1.0;

        public double BiasEnabled
        {
            get { return biasEnabled; }
            set { biasEnabled = value; }
        }

        internal IActivationFunction ActivationFunction
        {
            get { return function; }
            set { function = value; }
        }
        
        public double Error
        {
            get { return this.error; }
            set { this.error = value; }
        }

        public ActivationNeuron(IActivationFunction f) : base()
        {
            if (f == null) { throw (new NeuralNetworksException()); };
            error = 0.0;
            function = f;
        }

        public override void Compute()
        {
            _output = 0.0;
            foreach (Connection con in _inputs)
            {
                _output += con.Weight * con.N.Output;
            }
            _output += _biasWeight * biasEnabled;
            _output = function.Compute(_output);
        }
    }
}
